/*
 * @lc app=leetcode.cn id=876 lang=javascript
 *
 * [876] 链表的中间结点
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var middleNode = function (head) {
  // let len = 0
  // let tmp = head
  // while(tmp !== null) {
  //   tmp = tmp.next
  //   len++
  // }
  // len = (len / 2) | 0
  // left = 0
  // while(left < len) {
  //   head = head.next
  //   left++
  // }
  // return head
  let p = head, q = head
  while (q != null && q.next != null) {
    q = q.next.next
    p = p.next
  }
  return p
}
// @lc code=end

